﻿Imports System.Text.RegularExpressions

Namespace Operaties

    ''' <summary>
    ''' Alle operaties op Emails
    ''' </summary>
    Public Class EmailadressenBL

        Public Enum ResultType
            OK
            SlechtAdres
            BestondAl
            Fout
        End Enum

        Public Shared Function EmailadresToevoegen(ByVal email As String) As ResultType
            If (Not IsEmailadresGeldig(email)) Then Return ResultType.SlechtAdres
            Dim dal As New Dal()
            Try
                Dim returnvalue As Integer = dal.EmailadresToevoegen(email)
                If (returnvalue = 0) Then Return ResultType.BestondAl
                Return ResultType.OK
            Catch ex As Exception
                log.WriteError("Fout bij toevoegen e-mailadres", ex)
                Return ResultType.Fout
            End Try
        End Function

        Public Shared Function IsEmailadresGeldig(ByVal email As String) As Boolean
            Return Regex.IsMatch(email, "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}$")
        End Function

    End Class

End Namespace
